﻿<Window x:Class="NuGetReferenceSwitcher.Presentation.Views.MainDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:converters="clr-namespace:MyToolkit.Converters;assembly=MyToolkit.Extended"
        xmlns:viewModels="clr-namespace:NuGetReferenceSwitcher.Presentation.ViewModels"
        xmlns:converters1="clr-namespace:NuGetReferenceSwitcher.Presentation.Converters"
        Title="Switch NuGet and Project references" 
        Height="700" Width="800" ResizeMode="CanResizeWithGrip"
        WindowStartupLocation="CenterScreen">

    <Window.Resources>
        <viewModels:MainDialogModel x:Key="ViewModel" />
        <converters:NotConverter x:Key="NotConverter" />
        <converters:VisibilityConverter x:Key="VisibilityConverter" />
        <converters1:NuGetToProjectModeConverter x:Key="NuGetToProjectModeConverter" />
        <converters1:NotNuGetToProjectModeConverter x:Key="NotNuGetToProjectModeConverter" />
    </Window.Resources>

    <Grid DataContext="{StaticResource ViewModel}">
        <TextBlock Text="Please wait..." Margin="8" 
                   Visibility="{Binding IsLoading, Converter={StaticResource VisibilityConverter}}" />

        <TabControl Margin="0,12,0,0" Visibility="{Binding IsLoading, Converter={StaticResource NotConverter}}" x:Name="Tabs">
            <TabItem Header="Switch to Project references">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <TextBlock Text="NuGet to Project switches" Grid.Row="0" Grid.Column="0" 
                               FontWeight="Bold" FontSize="16" Margin="8" />
                    <ScrollViewer Grid.Row="1" Grid.Column="0">
                        <ItemsControl ItemsSource="{Binding Transformations}" Margin="8">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Margin="0,0,0,8">
                                        <TextBlock Text="{Binding FromAssemblyName}" ToolTip="{Binding FromAssemblyPath}" FontWeight="Bold" Margin="0,0,0,4" />

                                        <RadioButton IsChecked="{Binding SelectedMode, Mode=TwoWay, ConverterParameter='Deactivated', Converter={StaticResource NuGetToProjectModeConverter}}" 
                                                     GroupName="{Binding FromAssemblyName}"
                                                     Content="Do not replace" Margin="0,0,0,4" />

                                        <RadioButton IsChecked="{Binding SelectedMode, Mode=TwoWay, ConverterParameter='ProjectPath', Converter={StaticResource NuGetToProjectModeConverter}}" 
                                                     GroupName="{Binding FromAssemblyName}" Margin="0,0,0,4"
                                                     Content="Add new Project to Solution" />

                                        <RadioButton IsChecked="{Binding SelectedMode, Mode=TwoWay, ConverterParameter='Project', Converter={StaticResource NuGetToProjectModeConverter}}" 
                                                     GroupName="{Binding FromAssemblyName}"
                                                     Content="Use existing Project" />

                                        <StackPanel Visibility="{Binding SelectedMode, Mode=OneWay, ConverterParameter='Deactivated', Converter={StaticResource NotNuGetToProjectModeConverter}}" 
                                                    Margin="0,4,0,0">
                                            <StackPanel Visibility="{Binding SelectedMode, Mode=OneWay, ConverterParameter='ProjectPath', Converter={StaticResource NuGetToProjectModeConverter}}">
                                                <Button Content="Select Project to add" Click="OnSelectProjectFile" Tag="{Binding}" />
                                                <TextBlock Text="{Binding ToProjectPath}" TextWrapping="Wrap" Margin="0,4,0,0"
                                                           Visibility="{Binding ToProjectPath, Converter={StaticResource VisibilityConverter}}" />
                                            </StackPanel>

                                            <StackPanel Visibility="{Binding SelectedMode, Mode=OneWay, ConverterParameter='Project', Converter={StaticResource NuGetToProjectModeConverter}}">
                                                <ComboBox ItemsSource="{Binding Projects, Source={StaticResource ViewModel}}"
                                                          SelectedItem="{Binding ToProject, Mode=TwoWay}"
                                                          DisplayMemberPath="Name" />
                                            </StackPanel>
                                        </StackPanel>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>

                    <TextBlock Text="Scanned projects" FontWeight="Bold" FontSize="16" 
                               Grid.Row="0" Grid.Column="1" Margin="8" />
                    <ScrollViewer Grid.Row="1" Grid.Column="1">
                        <ItemsControl ItemsSource="{Binding Projects}" Margin="8">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Margin="0,0,0,8">
                                        <TextBlock Text="{Binding Name}" FontWeight="Bold" Margin="0,0,0,4" />
                                        <TextBlock Text="No NuGet references found." 
                                                   Visibility="{Binding NuGetReferences.Count, Converter={StaticResource NotConverter}}" />
                                        <ItemsControl ItemsSource="{Binding NuGetReferences}">
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Name}" Margin="0,0,0,4" />
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                        </ItemsControl>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>

                    <Button Grid.Row="2" Margin="8" Padding="4" Grid.Column="0" Grid.ColumnSpan="2"
                            Content="Switch to Project references" Click="OnSwitchToProjectReferences" />
                </Grid>
            </TabItem>
            <TabItem Header="Switch to NuGet references">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <TextBlock Text="Project to NuGet DLL switches" Grid.Row="0"
                               FontWeight="Bold" FontSize="16" Margin="8" />

                    <ScrollViewer Grid.Row="1">
                        <ItemsControl ItemsSource="{Binding Projects}" Margin="8">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Margin="0,0,0,8">
                                        <TextBlock Text="{Binding Name}" FontWeight="Bold" Margin="0,0,0,4" />
                                        <TextBlock Text="No references switched." 
                                                   Visibility="{Binding CurrentToNuGetTransformations.Count, Converter={StaticResource NotConverter}}" />
                                        <ItemsControl ItemsSource="{Binding CurrentToNuGetTransformations}">
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <TextBlock Margin="0,0,0,4" TextWrapping="Wrap">
                                                            <Run Text="From " FontWeight="Bold" />
                                                            <Run Text="{Binding FromProjectName}" />
                                                            <LineBreak />
                                                            <Run Text="To " FontWeight="Bold" />
                                                            <Run Text="{Binding ToAssemblyPath}" />
                                                    </TextBlock>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                        </ItemsControl>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>

                    <StackPanel Margin="8" Grid.Row="2">
                        <CheckBox Content="Remove Projects from Solution" Margin="0,0,0,8"
                                  IsChecked="{Binding RemoveProjects, Mode=TwoWay}" />
                        <Button Content="Switch to NuGet references" Click="OnSwitchToNuGetReferences" Padding="4" />
                    </StackPanel>
                </Grid>
            </TabItem>
            <TabItem Header="About">
                <StackPanel Margin="8">
                    <TextBlock Margin="0,0,0,8" FontSize="14">
                        NuGet Reference Switcher has been developed by 
                        <Hyperlink NavigateUri="http://www.rsuter.com" Click="OnOpenHyperlink">Rico Suter</Hyperlink>.
                    </TextBlock>
                    <TextBlock Margin="0,0,0,8" FontSize="14" FontWeight="Bold">
                        Read 
                        <Hyperlink NavigateUri="https://nugetreferenceswitcher.codeplex.com/wikipage?title=Guide" 
                                   Click="OnOpenHyperlink">this guide</Hyperlink>
                        about how to use the extension.
                    </TextBlock>
                    <TextBlock Margin="0,0,0,8">
                        Version: <Run Text="{Binding ExtensionVersion, Mode=OneWay}" />, 
                        License: <Hyperlink NavigateUri="https://nugetreferenceswitcher.codeplex.com/license" Click="OnOpenHyperlink">Ms-PL</Hyperlink>
                    </TextBlock>
                    <TextBlock Text="Components" FontWeight="Bold" Margin="0,0,0,4" />
                    <TextBlock Margin="0,0,0,4">
                        - <Hyperlink NavigateUri="http://mytoolkit.codeplex.com" Click="OnOpenHyperlink">MyToolkit</Hyperlink>: 
                          .NET library with MVVM classes, controls and more components.
                    </TextBlock>
                </StackPanel>
            </TabItem>
        </TabControl>
    </Grid>
</Window>
